import { reactive } from "vue";
import { getLookupByCodeApi } from "@/api/waybillManagement/workOrder";
import { getUserByPositionApi } from "@/api/managementCenter/departmentPersonnel";
import { getTreeChannelApi } from "@/api/configCenter/warehouseEntryChannel";
import { getListApi as outWarehouseBrokerIdsApi } from "@/api/configCenter/outBoundAgent/index";

import { TreeSelect } from "ant-design-vue";
const SHOW_CHILD = TreeSelect.SHOW_CHILD;
export const searchItemList: Array<SuperSearch.SearchItem> = [
  {
    type: "input",
    label: "工单号",
    keyName: "workOrderNo",
    placeholder: "请输入"
  },
  {
    type: "input",
    label: "运单号",
    keyName: "waybillNumList",
    placeholder: "支持批量(空格/逗号隔开)"
  },
  reactive<SuperSearch.SearchItem>({
    type: "cascader",
    label: "问题类型",
    keyName: "questionTypeList",
    optionsRequest: getLookupByCodeApi,
    optReqParams: "QUESTION_SCOPE",
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "label",
      value: "value",
      children: "children"
    },
    attrs: {
      multiple: true,
      showCheckedStrategy: SHOW_CHILD
    },
    options: []
  }),
  {
    type: "datetimerange",
    label: "创建时间",
    keyName: "depositTime"
  },
  {
    type: "select",
    label: "业务状态限制",
    keyName: "shipmentLimit",
    optConfig: {
      label: "name",
      value: "code"
    },
    options: [
      {
        name: "否",
        code: 0
      },
      {
        name: "是",
        code: 1
      }
    ]
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "业务员",
    keyName: "bizIdList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { position: "4", status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "cascader",
    label: "渠道",
    keyName: "channelIdList",
    optionsRequest: getTreeChannelApi,
    optReqParams: {},
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data || [];
      }
    },
    optConfig: {
      label: "label",
      value: "value",
      children: "children"
    },
    attrs: {
      multiple: true,
      showCheckedStrategy: SHOW_CHILD
    },
    options: []
  }),
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "代理",
    keyName: "outWarehouseBrokerIdList",
    optionsRequest: outWarehouseBrokerIdsApi,
    optReqParams: { pageNum: 1, pageSize: 999, beforePageNum: 0, name: "", total: 0, status: undefined },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    attrs: {
      mode: "multiple"
    },
    optConfig: {
      label: "name",
      value: "id"
    },
    options: []
  }),
  {
    type: "select",
    label: "状态",
    keyName: "selectStatusList",
    optConfig: {
      label: "name",
      value: "code"
    },
    options: [
      {
        name: "处理中",
        code: 1
      },
      {
        name: "处理完成",
        code: 2
      }
    ],
    attrs: {
      mode: "multiple"
    }
  },
  reactive<SuperSearch.SearchItem>({
    type: "select",
    label: "创建人",
    keyName: "createByList",
    optionsRequest: getUserByPositionApi,
    optReqParams: { status: 1, pageNum: 1, pageSize: 9999999, total: 0 },
    optReqCb: (res: Base.GeneraDataType, row: SuperSearch.SearchItem) => {
      const { code, data } = res;
      if (code === 200) {
        row.options = data.records || [];
      }
    },
    optConfig: {
      label: "username",
      value: "id"
    },
    attrs: {
      mode: "multiple"
    },

    options: []
  })
];

export const tableColumnMap: Base.GeneraDataType<Array<SuperTable.TableCoulmnItem | SuperTable.NestTableColumnItem>> = {
  "1": [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "workOrderNo",
      title: "工单号",
      minWidth: "150",
      renderSlot: "workOrderNo"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "140"
    },
    {
      field: "bizName",
      title: "业务员",
      minWidth: "110"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "outWarehouseBrokeName",
      title: "代理",
      minWidth: "120"
    },
    {
      field: "shipmentLimit",
      title: "业务状态",
      minWidth: "90",
      renderSlot: "shipmentLimit",
      sortable: true
    },
    {
      field: "itemNumberSum",
      title: "总件数",
      minWidth: "120"
    },
    {
      field: "lastHandleContent",
      title: "最新处理内容",
      minWidth: "120"
    },
    {
      field: "lastHandleTime",
      title: "最新处理时间",
      minWidth: "120",
      formatter: "formatDate"
    },
    {
      field: "questionScope",
      title: "问题范围",
      minWidth: "120",
      renderSlot: "questionScope"
    },
    {
      field: "questionType",
      title: "问题类型",
      minWidth: "120",
      renderSlot: "questionType",
      sortable: true
    },
    {
      field: "questionDesc",
      title: "问题描述",
      minWidth: "120"
    },
    {
      field: "createTime",
      title: "创建时间",
      minWidth: "120",
      formatter: "formatDate",
      sortable: true
    },
    {
      field: "createName",
      title: "创建人",
      minWidth: "120",
      sortable: true
    },
    {
      field: "action",
      title: "操作",
      minWidth: "120",
      renderSlot: "action"
    }
  ],
  "2": [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "workOrderNo",
      title: "工单号",
      minWidth: "150",
      renderSlot: "workOrderNo"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "140"
    },
    {
      field: "bizName",
      title: "业务员",
      minWidth: "110"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "outWarehouseBrokeName",
      title: "代理",
      minWidth: "120"
    },
    {
      field: "shipmentLimit",
      title: "业务状态",
      minWidth: "90",
      renderSlot: "shipmentLimit",
      sortable: true
    },
    {
      field: "itemNumberSum",
      title: "总件数",
      minWidth: "120"
    },
    {
      field: "lastHandleContent",
      title: "最新处理内容",
      minWidth: "120"
    },
    {
      field: "lastHandleTime",
      title: "最新处理时间",
      minWidth: "120",
      formatter: "formatDate"
    },
    {
      field: "questionScope",
      title: "问题范围",
      minWidth: "120",
      renderSlot: "questionScope"
    },
    {
      field: "questionType",
      title: "问题类型",
      minWidth: "120",
      renderSlot: "questionType",
      sortable: true
    },
    {
      field: "questionDesc",
      title: "问题描述",
      minWidth: "120"
    },
    {
      field: "createTime",
      title: "创建时间",
      minWidth: "120",
      formatter: "formatDate",
      sortable: true
    },
    {
      field: "createName",
      title: "创建人",
      minWidth: "120",
      sortable: true
    },
    {
      field: "action",
      title: "操作",
      minWidth: "120",
      renderSlot: "action"
    }
  ],
  "3": [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "workOrderNo",
      title: "工单号",
      minWidth: "150",
      renderSlot: "workOrderNo"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "140"
    },
    {
      field: "bizName",
      title: "业务员",
      minWidth: "110"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "outWarehouseBrokeName",
      title: "代理",
      minWidth: "120"
    },
    {
      field: "shipmentLimit",
      title: "业务状态",
      minWidth: "90",
      renderSlot: "shipmentLimit",
      sortable: true
    },
    {
      field: "itemNumberSum",
      title: "总件数",
      minWidth: "120"
    },
    {
      field: "lastHandleContent",
      title: "最新处理内容",
      minWidth: "120"
    },
    {
      field: "lastHandleTime",
      title: "最新处理时间",
      minWidth: "120",
      formatter: "formatDate"
    },
    {
      field: "questionScope",
      title: "问题范围",
      minWidth: "120",
      renderSlot: "questionScope"
    },
    {
      field: "questionType",
      title: "问题类型",
      minWidth: "120",
      renderSlot: "questionType",
      sortable: true
    },
    {
      field: "questionDesc",
      title: "问题描述",
      minWidth: "120"
    },
    {
      field: "createTime",
      title: "创建时间",
      minWidth: "120",
      formatter: "formatDate",
      sortable: true
    },
    {
      field: "createName",
      title: "创建人",
      minWidth: "120",
      sortable: true
    },
    {
      field: "action",
      title: "操作",
      minWidth: "120",
      renderSlot: "action"
    }
  ],
  "4": [
    {
      type: "checkbox",
      field: "checkbox",
      minWidth: "50"
    },
    {
      field: "workOrderNo",
      title: "工单号",
      minWidth: "150",
      renderSlot: "workOrderNo"
    },
    {
      field: "waybillNum",
      title: "运单号",
      minWidth: "140"
    },
    {
      field: "bizName",
      title: "业务员",
      minWidth: "110"
    },
    {
      field: "channelName",
      title: "渠道",
      minWidth: "140"
    },
    {
      field: "outWarehouseBrokeName",
      title: "代理",
      minWidth: "120"
    },
    {
      field: "shipmentLimit",
      title: "业务状态",
      minWidth: "90",
      renderSlot: "shipmentLimit",
      sortable: true
    },
    {
      field: "itemNumberSum",
      title: "总件数",
      minWidth: "120"
    },
    {
      field: "lastHandleContent",
      title: "最新处理内容",
      minWidth: "120"
    },
    {
      field: "lastHandleTime",
      title: "最新处理时间",
      minWidth: "120",
      formatter: "formatDate"
    },
    {
      field: "questionScope",
      title: "问题范围",
      minWidth: "120",
      renderSlot: "questionScope"
    },
    {
      field: "questionType",
      title: "问题类型",
      minWidth: "120",
      renderSlot: "questionType",
      sortable: true
    },
    {
      field: "questionDesc",
      title: "问题描述",
      minWidth: "120"
    },
    {
      field: "createTime",
      title: "创建时间",
      minWidth: "120",
      formatter: "formatDate",
      sortable: true
    },
    {
      field: "createName",
      title: "创建人",
      minWidth: "120",
      sortable: true
    },
    {
      field: "action",
      title: "操作",
      minWidth: "120",
      renderSlot: "action"
    }
  ]
};
